#-*- codeing = utf-8 -*-
#@Time : 2020/9/21 9:02
#@Author : 阳某
#@File : 函数操作.py
#@Software : PyCharm

# print(len('hello'))
# 定义一个计算字符串长度的函数
def count_len_str(s):
    '''
    计算字符串长度
    :param s:
    :return:
    '''
    length = 0
    for i in s:
        length += 1
    # print(length)
    return length
# count_len_str('hello')
# print(length)     调用函数之后，内存清理机制会把函数里面的变量清空
# lens = count_len_str('hello')
# print(lens)


# print(len(['heloo','world','!!!']))
def count_len_list(listt):
    '''
    计算列表长度
    :param listt:
    :return:
    '''
    num = 10
    length = 0
    for i in listt:
        length += 1
    # print(length)
    return length,num,111,'aaa',[1,2,3]     #返回值不唯一，可以是各种数据类型
# count_len_list(['heloo','world','!!!'])

# lens = count_len_list(['heloo','world','!!!'])
# print(lens)         #将结果返回到一个元组中

# lens,num,aa,bb,lil = count_len_list(['heloo','world','!!!'])
# print(lens,num,aa,bb,lil)         #分别返回

# def counter(listt):
#     '''
#     计算列表长度
#     :param listt:
#     :return:
#     '''
#     length = 0
#     for i in listt:
#         length += 1
#     # print(length)
#     #              #不写retrun，返回空值
#     return          #只写return,返回空值
#     print('函数结束了嘛！')    #return代表结束函数，不会执行之后的代码
# lens = counter(['heloo','world','!!!'])
# print(lens)

# 参数类别
# 1.位置参数
def mymax(x,y):
    '''
    比较大小
    :param x:
    :param y:
    :return:
    '''
    the_max = x if x>y else y
    return the_max
# the_max = mymax(9,99)
# print(the_max)
#
# # 2.关键字参数
# the_max = mymax(y=5,x=9)
# print(the_max)
#
# # 两者混用
# the_max = mymax(9,y=55)
# print(the_max)

# 3.默认参数
# def info(name,sex='male'):
#     print(name,sex)
# # info('haha','male')
# info('haha')
# info('hehe')
# info('heihei')
# info('nihao','female')

# 陷阱
# 默认参数如果是一个可变的数据类型
# def func(a,l=[]):
#     l.append(a)
#     print(l)
# func(1)     #[1]
# func(2)     #[1, 2]
# func(3)     #[1, 2,3]

# 动态参数  ，不定长参数
# def mysum(a,b,c,d):
#     the_sum = a+b+c+d
#     return the_sum
# the_sum = mysum(1,2,3,4)
# print(the_sum)

# def mysum1(*args):
#     the_sum = 0
#     print(args)     #元组
#     for i in args:
#         the_sum +=i
#     return the_sum
# the_sum = mysum1(1,2,3,4,5,6,7,8,9,10)
# print(the_sum)

# **kwargs
def info(**kwargs):
    print(kwargs)   #   字典
    print(kwargs['name'],kwargs['sex'])
info(name = 'make',sex = 'male')